// import menuModule from './menuModule'
/**
 * @component
 * @首页
 */
const Home = resolve => require(['@/views/home/home'],resolve);
const Main = resolve => require(['@/views/Main'],resolve);
const Childmain = resolve => require(['@/views/Childmain'],resolve);
const DataDictionary = resolve => require(['@/views/system/dataDictionary/dataDictionary'],resolve);
const RoleManagement = resolve => require(['@/views/system/roleManagement/roleManagement'],resolve);
const UserManagement = resolve => require(['@/views/system/userManagement/userManagement'],resolve);

export default (routers, data) => {

    console.log("datadata---")
    console.log(routers)
    console.log(data)
    console.log("datadata---")
    generaMenu(routers, data)
}
// 递归子节点
function generaMenu (routers, data,level) {
    if(!data || !(data instanceof Array)){
        return;
    }
    if(!level){
        level = 0;
    }
    level ++;
    data.forEach((item) => {
        let menu = Object.assign({}, item);
        
        if(menu.winName) {
            let att = menu.winName.split('.');
            let name = att[att.length - 1];

            let code = menu.winName.split('.').join('/');
            menu.name = menu.caption;


            if (menu.children === null || menu.children === [] || !menu.children) {

                menu.path = '/' + code;
                menu.children = [];
                menu.leaf = true;
                switch (name) {
                    case 'home':
                        menu.component = Home;
                        break;
                    case 'dataDictionary':
                        menu.component = DataDictionary;
                        break;
                    case 'roleManagement':
                        menu.component = RoleManagement;
                        break;
                    case 'userManagement':
                        menu.component = UserManagement;
                        break;
                    default:
                        menu.component = Home;
                        break;
                }
            }
            else {
                menu.path = '/' + code + '/';
                if (menu.parentMenuCode != 0) {
                    menu.component = Childmain;
                } else {
                    menu.component = Main;
                }
                menu.leaf = false;
            }
            // 这里考虑到没有子节点，根节点处理点击跳转
            if (item.children) {

                // menu.smallIcon = 'iconmenu-renwuliebiao';// 测试用
                menu.smallIcon =  'iconfont ' + menu.smallIcon;
                if(level>1){
                    menu.smallIcon += ' level'+level+'Menu';
                }
                menu.smallIcon += menu.smallIcon;
                menu.children = [];

                generaMenu(menu.children, item.children,level)
            } else {
                // menu.smallIcon = 'iconmenu-shouye';// 测试用
                menu.smallIcon =  'iconfont ' + menu.smallIcon;
                if(level>1){
                    menu.smallIcon += ' level'+level+'Menu';
                }
                menu.smallIcon += menu.smallIcon;
            }

            routers.push(menu)
        }
    })
}
